package engine;



import java.awt.Color;

import physics.Collider;
import physics.Collider.ColliderType;
import physics.Collision;
import renderer.RenderObject;
import renderer.RenderObject.Primitive;
import renderer.Renderer;
import math.Vec2;

public class Engine{
	private Renderer renderer;
	
	private RenderObject obj;
	
	public boolean Initialize(){
		renderer = new Renderer();
		
		//obj = new RenderObject(100, 100, 100, 100, Color.RED);
		
		return true;
	}
	
	public void Shutdown(){
		renderer.Close();
	}
	
	public boolean Frame(){
		long startTime = System.currentTimeMillis();
		
		// Input

		// Logic
		Collider body1 = new Collider();
		body1.pos.Set(400, 300);
		body1.size.Set(4, 4);
		body1.radius = 50;
		body1.type = ColliderType.CIRCLE;
		RenderObject obj1 = new RenderObject();
        obj1.CreateCircle(400, 300, 50, Color.RED);
        
		
		Collider body2 = new Collider();
		body2.pos.Set(490, 300);
		body2.size.Set(4, 4);
		body2.radius = 50;
		body2.type = ColliderType.CIRCLE;
		RenderObject obj2 = new RenderObject();
        obj2.CreateCircle(490, 300, 50, Color.BLUE);

		/*Vec2 normal = Collision.CheckCollision(body1, body2);
		
        System.out.print("Normal: ");
		System.out.print(normal.x);
		System.out.print(" ");
		System.out.println(normal.y);*/
        
        boolean FIUCKING_WORK = Collision.CircleCollision(body1, body2);
        System.out.print("Collision: ");
        System.out.println(FIUCKING_WORK);
		
		// Render
		renderer.DrawObject(obj1);
		renderer.DrawObject(obj2);
		
		renderer.SwapBuffers();
		// 60 FPS Cap
		long endTime = System.currentTimeMillis();
		
		if(endTime - startTime < 16.66){
			try{
				Thread.sleep((long)16.66 - (endTime - startTime));
			}catch(InterruptedException e){
				e.printStackTrace();
			}
		}
        
        System.out.println("");
        
		//System.out.println(renderer.screen.detector.keyboard.keys[1]);
		return !renderer.screen.detector.keyboard.keys[1]; // If not exploding
	}
}
